home *** CD-ROM | disk | FTP | other *** search
- /* SETFTIME.C --- p. 665 */
- #include <stdio.h>
- #include <fcntl.h>
- #include <io.h>
- main()
- {
- char fname[40], *p_fname;
- int filehandle;
- unsigned date, time, day, month, year, hour, minute, second;
- struct ftime dtinfo;
- printf("Enter name of an existing file: ");
- p_fname = gets(fname);
- /* Open the file using _open */
- if((filehandle = _open(p_fname, O_RDONLY)) == -1)
- {
- printf("Error opening file: %s\n", fname);
- exit(0);
- }
- printf("File %s opened.\n", fname);
- /*Ask for new date and time stamp */
- printf("Enter new date in the format MM-DD-YY:");
- scanf("%u-%u-%u", &month, &day, &year);
- printf("Enter new time in the format HH:MM:SS ");
- scanf("%u:%u:%u", &hour, &minute, &second);
- /* Pack date and time information into single words */
- dtinfo.ft_tsec = second/2;
- dtinfo.ft_min = minute;
- dtinfo.ft_hour = hour;
- dtinfo.ft_day = day;
- dtinfo.ft_month = month;
- /* NOTE : Year is relative to 1980
- * So we are subtracting 80. */
- dtinfo.ft_year = year - 80;
- /* Set the date and time stamp */
- setftime(filehandle, &dtinfo);
- /* Get file's date and time stamp to verify the new
- * date and time */
- getftime(filehandle, &dtinfo);
- /* Now extract the time and date infomation */
- second = 2 * dtinfo.ft_tsec;
- minute = dtinfo.ft_min;
- hour = dtinfo.ft_hour;
- day = dtinfo.ft_day;
- month = dtinfo.ft_month;
- /* NOTE: year is reletive to 1980. So we are adding 80 */
- year = dtinfo.ft_year + 80;
- printf("File: %s Date: %d-%d-%d Time: %.2d:%.2d:%.2d\n",
- fname, month, day, year, hour, minute, second);
- /* Now close the file */
- if(_close(filehandle) != 0)
- {
- printf("Error closing file with _close\n");
- exit(0);
- }
- printf("File %s closed.\n", fname);
- }